package com.llc.gulimall.ware.listener;

import com.alibaba.fastjson.TypeReference;
import com.llc.common.to.mq.OrderTo;
import com.llc.common.to.mq.StockDetailTo;
import com.llc.common.to.mq.StockLockedTo;
import com.llc.common.utils.PageUtils;
import com.llc.common.utils.R;
import com.llc.gulimall.ware.entity.WareOrderTaskDetailEntity;
import com.llc.gulimall.ware.entity.WareOrderTaskEntity;
import com.llc.gulimall.ware.feign.OrderFeignService;
import com.llc.gulimall.ware.service.WareOrderTaskDetailService;
import com.llc.gulimall.ware.service.WareOrderTaskService;
import com.llc.gulimall.ware.service.WareSkuService;
import com.llc.gulimall.ware.vo.OrderVo;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * @author llc
 * @Description
 * @Version
 * @date 2022/2/17 21:36
 */
//@Slf4j
//@Service
//@RabbitListener(queues = "stock.release.stock.queue")
//public class StockReleaseListener {
//    @Autowired
//    WareOrderTaskService orderTaskService;
//
//    @Autowired
//    WareOrderTaskDetailService orderTaskDetailService;
//
//    @Autowired
//    OrderFeignService orderFeignService;
//
//    @Autowired
//    WareSkuService wareSkuService;
//
//    //处理消息方法,库存自动解锁
//
//    /**
//     * @param to
//     * @param message
//     * @return void
//     * @author llc
//     * @description //处理消息方法,库存自动解锁
//     * @date 2022/2/17 18:59
//     */
//    @RabbitHandler
//    public void handleStockLockedRelease(StockLockedTo to, Message message, Channel channel) throws IOException {
//        System.out.println("收到解锁库存消息");
//        try {
//            wareSkuService.unlockStock(to);
//            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//        } catch (Exception e) {
//            channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
//        }
//    }
//    //尝试方法重载
//    @RabbitHandler
//    //public void handleOrderCloseRelease(OrderTo orderTo, Message message, Channel channel) throws IOException {
//    public void handleOrderCloseRelease(OrderTo orderTo, Message message, Channel channel) throws IOException {
//        System.out.println("订单关闭消息,准备解锁库存");
//        try {
//            wareSkuService.unlockStock(orderTo);
//            log.info("订单已经解锁");
//            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
//        } catch (Exception e){
//            //失败拒绝
//            channel.basicReject(message.getMessageProperties().getDeliveryTag(), true);
//        }
//    }
//}
